<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href=../res/adminui/dist/img/hzzc.png>
    <meta charset="utf-8">
    <title>璞′笂鎶曠爺绯荤粺</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="../res/layui/css/layui.css?v=1.32" rel="stylesheet">
    <link href="../res/adminui/dist/css/admin.css?v=1.32" rel="stylesheet">
    <script>
        /^http(s*):\/\//.test(location.href) || alert('璇烽�氳繃 localhost 璁块棶');
    </script>
</head>
<body class="layui-layout-body">
<div id="LAY_app">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <!-- 澶撮儴鍖哄煙 -->
            <ul class="layui-nav layui-layout-left">
                <li class="layui-nav-item layadmin-flexible" lay-unselect>
                    <a href="javascript:;" layadmin-event="flexible" title="渚ц竟浼哥缉">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
                    </a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" layadmin-event="refresh" title="鍒锋柊">
                        <i class="layui-icon layui-icon-refresh-3"></i>
                    </a>
                </li>
                <li style="left:110%;width: 300px;" class="layui-nav-item layui-hide-xs" lay-unselect>
                    <div class="layui-form-item layui-form" style="max-width: 300px;margin-top:5px;color: #4d4040">
                        <select id="index-select-view" type="text" lay-filter="index-select-view" lay-verify="required"
                                lay-search="">
                            <option value="">璇疯緭鍏ヨ彍鍗曞悕绉�</option>
                        </select>
                    </div>
                </li>
            </ul>
            <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="fullscreen">
                        <i class="layui-icon layui-icon-screen-full"></i>
                    </a>
                </li>
                <li style="margin-right: 10px;" class="layui-nav-item" lay-unselect>
                    <a href="javascript:;">
                        <cite id="index_user_name"></cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd layadmin-event="logout" style="text-align: center;"><a>閫�鍑�</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <!-- 渚ц竟鑿滃崟 -->
        <div class="layui-side layui-side-menu">
            <div class="layui-side-scroll">
                <script type="text/html" template lay-url="/start/menu"
                        lay-done="layui.element.render('nav', 'layadmin-system-side-menu');" id="TPL_layout">
                    <div class="layui-logo">
                        <span id="index_layui_setter_name">璞′笂鎶曠爺绯荤粺</span>
                    </div>
                    <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu"
                        lay-filter="layadmin-system-side-menu">
                        <li data-name="home" class="layui-nav-item layui-nav-itemed">
                            <a t-type="1" lay-href="/iframe/views/home/console.html" lay-tips="涓婚〉" lay-direction="2">涓婚〉
                                <i class="layui-icon layui-icon-home"></i>
                            </a>
                        </li>
                        {{#
                        layui.each(d.data, function(index, item){
                        }}
                        <li data-name="component" class="layui-nav-item">
                            <a href="javascript:;" lay-direction="2">
                                <i class="layui-icon layui-icon-component"></i>
                                <cite>{{item.title}}</cite>
                            </a>
                            {{#
                            var data2=item.list;
                            if(data2.length>0){
                            layui.each(data2,function(index, item2){
                            var
                            url2=item2.jump.replace("/oa-st","/iframe/views/oa-st").replace("/oa-sys","/iframe/views/oa-sys");
                            }}
                            <dl class="layui-nav-child">
                                <dd data-name="content">
                                    {{#
                                    var data3=item2.list;
                                    if(data3.length>0){
                                    }}
                                    <a href="javascript:;">{{item2.title}}</a>
                                    <dl class="layui-nav-child">
                                        {{#
                                        layui.each(data3,function(index, item3){
                                        var
                                        url3=item3.jump.replace("/oa-st","/iframe/views/oa-st").replace("/oa-sys","/iframe/views/oa-sys");
                                        }}
                                        <dd data-name="list">
                                            <a t-type="3" lay-href="{{url3}}.html">{{item3.title}}</a>
                                        </dd>
                                        {{# });}}
                                    </dl>
                                    {{#
                                    }else{
                                    }}
                                    <a t-type="2" lay-href="{{url2}}.html">{{item2.title}}</a>
                                    {{#} }}
                                </dd>
                            </dl>
                            {{# });} }}
                        </li>
                        {{#});}}
                    </ul>
                </script>
            </div>
        </div>

        <!-- 椤甸潰鏍囩�� -->
        <div class="layadmin-pagetabs" id="LAY_app_tabs">
            <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-down">
                <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
                    <li class="layui-nav-item" lay-unselect>
                        <a href="javascript:;"></a>
                        <dl class="layui-nav-child layui-anim-fadein">
                            <dd layadmin-event="closeThisTabs"><a href="javascript:;">鍏抽棴褰撳墠鏍囩�鹃〉</a></dd>
                            <dd layadmin-event="closeOtherTabs"><a href="javascript:;">鍏抽棴鍏跺畠鏍囩�鹃〉</a></dd>
                            <dd layadmin-event="closeAllTabs"><a href="javascript:;">鍏抽棴鍏ㄩ儴鏍囩�鹃〉</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
            <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
                <ul class="layui-tab-title" id="LAY_app_tabsheader">
                    <li lay-id="/iframe/views/home/console.html" lay-attr="/iframe/views/home/console.html"
                        class="layui-this"><i class="layui-icon layui-icon-home"></i></li>
                </ul>
            </div>
        </div>

        <!-- 涓讳綋鍐呭�� -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <iframe id="hzzc_iframe" src="" frameborder="0" class="layadmin-iframe"></iframe>
            </div>
        </div>

        <div id="floating-window" class="floating-window" content="">

        </div>
        <!-- 杈呭姪鍏冪礌锛屼竴鑸�鐢ㄤ簬绉诲姩璁惧�囦笅閬�缃� -->
        <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>
    <audio id="fund_pop_notice">
        <source src="../res/style/imgs/5c8950ddeee1e64812.mp3" type="audio/mpeg">
    </audio>
</div>
<div class="layui-card" style="padding-bottom: 5px;" id="index_fund_notice_window">
</div>
<script src="../res/layui/layui.js?t=1.1"></script>
<script  src="../res/modules/socket.io.js"></script>
<script>
    layui.config({
        base: '../res/', // 闈欐�佽祫婧愭墍鍦ㄨ矾寰�
        version: 1.93
    }).use(['index', 'admin', 'form', 'user', 'hzzcUtil'], function () {
        var $ = layui.$, setter = layui.setter, admin = layui.admin, form = layui.form;
        var indexUrl = window.location.href;
        if (indexUrl.indexOf("?v=") < 0) {
            window.location.href = indexUrl + "?v=" + setter.layVersion;
        } else {
            var param = indexUrl.split("?")[1].replace("v=", "");
            if (parseFloat(param) !== parseFloat(setter.layVersion)) {
                window.location.href = indexUrl.split("?")[0] + "?v=" + setter.layVersion;
            }
        }
        admin.req({
            url: setter.ipAddress + "/start/permission",
            method: "get",
            async: false,
            success: (data) => {
                window.permission = new Set(data.data);
                window.userId = data.ext ? data.ext.userId : null;
                window.userName = data.ext ? data.ext.userName : null;
                layui.data(setter.tableName3, {key: 'permission', value: data.data});
                layui.data(setter.tableName3, {key: 'userId', value: window.userId});
                layui.data(setter.tableName3, {key: 'userName', value: window.userName});
                $("#index_user_name").text(window.userName);
            }
        });
        var isNotice=false;
        updSelect();
        function  updSelect(){
            var map = {};
            admin.req({
                url: setter.ipAddress + "/start/menu",
                method: "get",
                async: false,
                success: (data) => {
                    layui.each(data.data, function (index, item) {
                        layui.each(item.list, function (index2, item2) {
                            if (item2.list.length < 1) {
                                map[item2.jump] = item2.name;
                            } else {
                                layui.each(item2.list, function (index3, item3) {
                                    map[item3.jump] = item3.name;
                                });
                            }
                            if(item2.name==="淇″彿娑堟伅鍒楄〃"){
                                isNotice=true;
                            }
                        });
                    });
                    form.render();
                }
            });

            admin.req({
                url: setter.timeAddress + "/userRedis/query?key=console_user_view_read_" + window.userId,
                method: "get",
                async: false,
                success: (data) => {
                    var res = JSON.parse(data.data);
                    for (var i = res.length - 1; i >= 0; i--) {
                        var bz = res[i].replace("/iframe/views", "").replace(".html", "");
                        if (bz in map) {
                            $("#index-select-view").append("<option   value='" + bz + "'>" + map[bz].substr(0, 18) + "</option>");
                            delete   map[bz];
                        }
                    }
                    for(var str in map){
                        $("#index-select-view").append("<option   value='" + str + "'>" + map[str].substr(0, 18) + "</option>");
                    }
                    form.render();
                }
            });
        }
        form.on('select(index-select-view)', function (data) {
            $("#LAY-system-side-menu li").removeClass("layui-nav-itemed");
            $("#LAY-system-side-menu li dl dd").removeClass("layui-nav-itemed");
            if (data.value.length > 0) {
                var url = "/iframe/views" + data.value + ".html";
                $("#LAY-system-side-menu li dl dd a").each(function () {
                    if ($(this).attr("lay-href") === url) {
                        var liz = $(this).parents("li");
                        $(liz).addClass("layui-nav-itemed");
                        if ($(this).attr("t-type") === "3") {
                            var dlz = $(this).parents("dd");
                            $(dlz).addClass("layui-nav-itemed");
                        }
                        $(this).click();
                    }
                });
                $("#index-select-view").find("option").eq(0).prop("selected", true);
                form.render();
            }
        });
        $(window.parent.document).find("#hzzc_iframe").attr("src", "/iframe/views/home/console.html");


        //杩炴帴trade鏈嶅姟鍣�
        connectTradeServer();

        function connectTradeServer() {

            class ReconnectingWebSocket {
                constructor(url, options = {}) {
                    this.url = url;
                    this.reconnectDelay = options.reconnectDelay || 2000; // 鍒濆�嬮噸杩為棿闅旓紙姣�绉掞級
                    this.maxReconnectAttempts = options.maxReconnectAttempts || 10; // 鏈�澶ч噸杩炴�℃暟
                    this.currentReconnectAttempts = 0;
                    this.onOption = options.onOption || {}
                    this.ping = options.ping || (() => {
                    })
                    this.connect();
                    this.ping.apply(this)
                }

                message(event) {
                    let data = event.data
                    let message = this.onOption["message"]
                    if (message) {
                        message.call(this, data)
                    } else {
                        let json = JSON.parse(data)
                        let eventType = json["event"]
                        if (eventType && this.onOption[eventType]) {
                            this.call_(eventType, data)
                        }
                    }
                }

                call_(method, data) {
                    let m_ = this.onOption[method]
                    if (m_) {
                        m_.call(this, data);
                    }
                }

                on(type, method) {
                    //缁戝畾鍑芥暟
                    if (method) {
                        this.onOption[type] = method
                    }
                }

                connect() {
                    this.socket = new WebSocket(this.url);

                    // 杩炴帴鎴愬姛浜嬩欢
                    this.socket.onopen = () => {
                        this.currentReconnectAttempts = 0; // 閲嶇疆閲嶈繛娆℃暟
                        this.call_("open")
                    };

                    // 鎺ユ敹娑堟伅浜嬩欢
                    this.socket.onmessage = (event) => {
                        this.message(event)
                    };

                    // 杩炴帴鍏抽棴浜嬩欢
                    this.socket.onclose = (event) => {
                        this.call_("close", event)
                        this.reconnect();
                    };

                    // 杩炴帴閿欒��浜嬩欢
                    this.socket.onerror = (error) => {
                        this.call_("error", error)
                        this.socket.close(); // 瑙﹀彂 `onclose` 浠ヨ繘琛岄噸杩�
                    };
                }

                reconnect() {
                    if (this.currentReconnectAttempts >= this.maxReconnectAttempts) {
                        console.error("Max reconnect attempts reached. Giving up.");
                        return;
                    }

                    this.currentReconnectAttempts++;
                    const delay = this.reconnectDelay * this.currentReconnectAttempts; // 鎸囨暟閫�閬匡紙鍙�閫夛級
                    setTimeout(() => {
                        this.connect();
                    }, delay);
                }

                send(data) {
                    if (this.socket.readyState === WebSocket.OPEN) {
                        this.socket.send(data);
                    } else {
                        console.warn("Cannot send message. WebSocket is not open.");
                    }
                }

                close() {
                    this.socket.close();
                }
            }

            function handleMessage(data) {
                let iframes = document.querySelectorAll('iframe');

                for (let i = 0; i < iframes.length; i++) {
                    let iframe = iframes[i];
                    if (iframe.src.indexOf("oa-st/ctp/ctp") > -1) {
                        try {
                            iframe.contentWindow.postMessage(JSON.parse(data), '*');
                        } catch (e) {
                            iframe.contentWindow.postMessage(data, '*');
                        }
                    }
                }
            }

            function pingCall() {
                let socket = this
                setInterval(() => {
                    socket.send(JSON.stringify({"type": "ping"}))
                }, 1000)
            }

            const socket = new ReconnectingWebSocket(setter.tradeWsIp, {
                reconnectDelay: 5000,
                maxReconnectAttempts: 5000,
                ping: pingCall,
                onOption: {
                    "message": handleMessage,
                },
            });

            socket.on("open", function () {
                layer.msg("杩炴帴鍒版湇鍔″櫒:" + setter.tradeWsIp);
            })

            socket.on('error', function () {
                console.log("鏃犳硶杩炴帴浜ゆ槗鏈嶅姟鍣�")
            });

        }

        //鎵撳紑涓婃�￠粯璁ら�夐」鍗�
        if(isNotice) {
            tSocket();
            function tSocket() {
                console.log("鍚�鍔ㄦ湇鍔″櫒杩炴帴");
                const socket = io(setter.wsIp,
                    {
                        upgrade: false, reconnection: true,
                        reconnectionAttempts: Infinity,
                        reconnectionDelay: 1000,
                        reconnectionDelayMax: 2000, transports: ["websocket"]
                    });
                socket.on("connect", function () {
                    layer.msg("杩炴帴鍒版湇鍔″櫒:" + setter.wsIp);
                    const user = {};
                    user.name = window.userName;
                    user.id = window.userId;
                    socket.emit('message', JSON.stringify(user));
                })
                socket.on('connect_error', function () {
                    layer.msg("鏃犳硶杩炴帴鍒版湇鍔″櫒");
                });
                socket.on('fundIndexNotice-info',function (result){
                    var iframes = document.querySelectorAll('iframe');
                    var nowIframe=null;
                    for (var i = 0; i < iframes.length; i++) {
                        var iframe = iframes[i];
                        if(iframe.src.indexOf("/iframe/views/oa-st/util/fundIndexNotice.html")>-1){
                            nowIframe=iframe;
                            console.log('iframe ' + i + ': ' + iframe.src);
                            break;
                        }
                    }
                    if(null!=nowIframe){
                        let data={};
                        data.content=result;
                        data.type=1;
                        nowIframe.contentWindow.postMessage(data,'*');
                    }
                });
                socket.on('fund-trade-notice-info',function (result){
                    var iframes = document.querySelectorAll('iframe');
                    var nowIframe=null;
                    for (var i = 0; i < iframes.length; i++) {
                        var iframe = iframes[i];
                        if(iframe.src.indexOf("/iframe/views/oa-st/util/fundIndexNotice.html")>-1){
                            nowIframe=iframe;
                            console.log('iframe ' + i + ': ' + iframe.src);
                            break;
                        }
                    }
                    if(null!=nowIframe){
                        let data={};
                        data.content=result;
                        data.type=2;
                        nowIframe.contentWindow.postMessage(data,'*');
                    }
                });
                socket.on('fundIndexNotice', function (data) {
                    var fundIndex = JSON.parse(data);
                    const times = new Date().getTime();
                    var str = "<div  style=\" width: 270px; padding-top: 10px;margin-left: 30px;\">\n   " +
                        " <span class=\"index_span_width index_span_width_title\" >鍚堢害:</span><span class=\"index_span_width index_span_width_value\" style='color: red'>" + fundIndex.code + "</span>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >鍛ㄦ湡:</span><span class=\"index_span_width index_span_width_value\" style='color: blue'>" + fundIndex.zhouqi + "</span><br>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >绫诲瀷:</span><span class=\"index_span_width index_span_width_value\" style='color: green'>" + fundIndex.inform + "</span>\n   " +
                        " <span class=\"index_span_width index_span_width_title\">鍘嗗彶鑳滅巼:</span><span class=\"index_span_width index_span_width_value\"  style='color: orange'>" + isNullBig(fundIndex.shenglv) + "</span>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >骞村唴鑳滅巼:</span><span class=\"index_span_width index_span_width_value\" style='color: orange'>" + isNullBig(fundIndex.yearShenglv) + "</span><br><br>\n   " +
                        " <span class=\"index_span_width2 index_span_width_title\" style='color: red'>璇存槑:" + fundIndex.tag + "</span>\n</div>";
                    layer.open({
                        type: 1, // 寮瑰嚭灞傜被鍨嬶紝0涓洪粯璁ゆ牱寮忥紝1涓篿frame
                        id: times,
                        title: "K绾垮舰鎬� " + fundIndex.tradeTime, // 寮瑰嚭灞傛爣棰�
                        content: str, // 寮瑰嚭灞傚唴瀹�
                        area: ["300px", "240px"] // 寮瑰嚭灞傚�介珮
                    });
                    if($("#newsTextId").length > 0){
                        var noteType="";
                        $(".index-notice-button-kpi").each(function (){
                            if(!$(this).hasClass("index_notice_button_un_checked")){
                                noteType=$(this).attr("text_name");
                            }
                        });
                        if(noteType==="fundIndexNotice"){
                            var str2="";
                            str2+= "<li>"
                            str2 += "<div class=\"newsTimer\" > " +timeFormat(new Date().getTime())+" "+ fundIndex.tradeTime + "</div>";
                            str2 += "<div class=\"newsDetail\" > 鍚堢害: <span style='color: red'>" + fundIndex.code + "</span>" +
                                " 鏁版嵁鍛ㄦ湡:<span style='color: blue'>" + fundIndex.zhouqi + "</span> " +
                                " K绾跨被鍨�:<span style='color: green'>" + fundIndex.inform + "</span>  " +
                                "鍘嗗彶鑳滅巼:<span style='color: orange'>" + isNullBig(fundIndex.shenglv) + "</span>  " +
                                "骞磋儨鐜�:<span style='color: orange'>" + isNullBig(fundIndex.yearShenglv) + "</span> " +
                                "璇存槑:<span style='color: red'>" + fundIndex.tag + "</span></div>"
                            str2 += "</li>";
                            $("#newsTextId").prepend(str2);
                        }
                    }else{
                        console.log("鏈�鎵撳紑娑堟伅鍒楄〃");
                    }
                });
                socket.on("pop",function (data){
                    document.getElementById("fund_pop_notice").play();
                });
                socket.on("fund-trade-notice",function (data){
                    var fundTradeResult = JSON.parse(data);
                    const times = new Date().getTime();
                    var str = "<div  style=\" width: 270px; padding-top: 10px;margin-left: 30px;\">\n   " +
                        " <span class=\"index_span_width index_span_width_title\" >鍚堢害:</span><span class=\"index_span_width index_span_width_value\" style='color: red'>" + fundTradeResult.instrument + "</span>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >寮�骞充粨:</span><span class=\"index_span_width index_span_width_value\" style='color: blue'>" + fundTradeResult.openClose + "</span><br>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >澶氱┖:</span><span class=\"index_span_width index_span_width_value\" style='color: green'>" + fundTradeResult.buySell + "</span>\n   " +
                        " <span class=\"index_span_width index_span_width_title\">鏁伴噺:</span><span class=\"index_span_width index_span_width_value\"  style='color: orange'>" + fundTradeResult.number + "</span>\n    " +
                        "<span class=\"index_span_width index_span_width_title\" >鎴愪氦鏁伴噺:</span><span class=\"index_span_width index_span_width_value\" style='color: orange'>"+ fundTradeResult.tradeNumber +"</span>\n   " +
                        "<span class=\"index_span_width index_span_width_title\" >澶辫触鏁伴噺</span><span class=\"index_span_width index_span_width_value\" style='color: red'>"+fundTradeResult.cancelNumber+"</span><br><br></div>\n   ";
                    layer.open({
                        type: 1, // 寮瑰嚭灞傜被鍨嬶紝0涓洪粯璁ゆ牱寮忥紝1涓篿frame
                        id: times,
                        title: '鏃ュ唴浣庨�� ' + fundTradeResult.createDate, // 寮瑰嚭灞傛爣棰�
                        content: str, // 寮瑰嚭灞傚唴瀹�
                        area: ['300px', '240px'] // 寮瑰嚭灞傚�介珮
                    });
                    if($("#newsTextId").length > 0){
                        var noteType="";
                        $(".index-notice-button-kpi").each(function (){
                            if(!$(this).hasClass("index_notice_button_un_checked")){
                                noteType=$(this).attr("text_name");
                            }
                        });
                        if(noteType==="fund-trade-notice"){
                            var str2="";
                            str2 += "<li>"
                            str2 += "<div class=\"newsTimer\" > " + timeFormat(new Date().getTime())+" "+fundTradeResult.createDate + "</div>";
                            str2 += "<div class=\"newsDetail\" > 鍚堢害: <span style='color: red;padding-right: 30px;'>" + fundTradeResult.instrument + "</span>" +
                                " 寮�骞充粨:<span style='color: green;padding-right: 30px;'>" + fundTradeResult.openClose+ "</span>  " +
                                " 鏂瑰悜:<span style='color: blue;padding-right: 30px;'>" + fundTradeResult.buySell + "</span> " +
                                " 浜ゆ槗鏁伴噺:<span style='color: orange;padding-right: 30px';> " +fundTradeResult.number  + "</span>  " +
                                " 鎴愪氦鏁伴噺:<span style='color: orange;padding-right: 30px';> " + fundTradeResult.tradeNumber + "</span> " +
                                " 澶辫触鏁伴噺:<span style='color: red'>" + fundTradeResult.cancelNumber + "</span></div>"
                            str2 += "</li>";
                            $("#newsTextId").prepend(str2);
                        }
                    }else{
                        console.log("鏈�鎵撳紑娑堟伅鍒楄〃");
                    }
                });
            }

            function isNullBig(rate) {
                if (null === rate || undefined === rate) {
                    return "";
                } else {
                    return (rate*100).toFixed(2)+"%";
                }
            }

            $("#floating-window").click(function () {
                const times = new Date().getTime();
                var isOpen=true;
                var isPop=true;
                var isOpen2=true;
                var isPop2=true;
                var str=" <div class=\"layui-card-header\" >\n         <div style=\"padding-left: 40%;float: left;width: 150px;\">\n            <button type=\"button\" class=\"layui-btn layui-btn-sm index-notice-button-kpi\" text_name=\"fundIndexNotice\" style=\"margin: 0;\">K绾垮舰鎬�</button>\n            <button  text_name=\"fund-trade-notice\"  type=\"button\" style=\"margin-left: -5px;\" class=\" index_notice_button_un_checked layui-btn layui-btn-sm index-notice-button-kpi\">鏃ュ唴浣庨��</button>\n        </div>\n        <div style=\"float:right;width: 200px;\">\n            <form class=\"layui-form\">\n                <div class=\"layui-form-item\">\n                    <div class=\"layui-input-block\" style=\"margin-left: 0;\" id=\"index-notice-button-kpi-dis\">\n                        <input type=\"checkbox\" id=\"index_fund_notice_open_id\"   name=\"switch\" lay-filter=\"fund_index_notice_flag1\"  lay-skin=\"switch\" lay-text=\"鍏抽棴寮圭獥|寮�鍚�寮圭獥\">\n                        <input type=\"checkbox\"   id=\"index_fund_notice_pop_id\" name=\"switch\" lay-filter=\"fund_index_notice_flag2\" lay-skin=\"switch\" lay-text=\"鍏抽棴澹伴煶|寮�鍚�澹伴煶\">\n                    </div>\n                    <div class=\"layui-input-block\" style=\"margin-left: 0;display: none;\" id=\"index-notice-button-kpi-dis2\" >\n                        <input type=\"checkbox\" id=\"index_fund_notice_open_id2\"   name=\"switch\" lay-filter=\"fund_index_notice_flag3\"  lay-skin=\"switch\" lay-text=\"鍏抽棴寮圭獥|寮�鍚�寮圭獥\">\n                        <input type=\"checkbox\"   id=\"index_fund_notice_pop_id2\" name=\"switch\" lay-filter=\"fund_index_notice_flag4\" lay-skin=\"switch\" lay-text=\"鍏抽棴澹伴煶|寮�鍚�澹伴煶\">\n                    </div>\n                </div>\n            </form>\n        </div>\n    </div>\n    <div class=\"layui-card-body\" style=\"width: 635px;max-height: 400px;\">\n        <ul class=\"newsText all\" id=\"newsTextId\">;\n        </ul>\n    </div>";
                $("#index_fund_notice_window").html(str);
                admin.req({
                    url: setter.timeAddress+"/noticeUser/query",
                    data:{userId:window.userId,noticeType:'fundIndexNotice'},
                    method: "get",
                    async: false,
                    success: function (res) {
                        console.log(res);
                        if(res.data!=="" && null!=res.data){
                            isOpen=res.data.isOpen !== 1;
                            isPop=res.data.isPop !== 1;
                        }
                    }
                });
                admin.req({
                    url: setter.timeAddress+"/noticeUser/query",
                    data:{userId:window.userId,noticeType:'fund-trade-notice'},
                    method: "get",
                    async: false,
                    success: function (res) {
                        console.log(res);
                        if(res.data!=="" && null!=res.data){
                            isOpen2=res.data.isOpen !== 1;
                            isPop2=res.data.isPop !== 1;
                        }
                    }
                });
                if(isOpen) {
                    $("#index_fund_notice_open_id").attr("checked", "checked");
                }
                if(isOpen2) {
                    $("#index_fund_notice_open_id2").attr("checked", "checked");
                }
                if(isPop) {
                    $("#index_fund_notice_pop_id").attr("checked", "checked");
                }
                if(isPop2) {
                    $("#index_fund_notice_pop_id2").attr("checked", "checked");
                }
                admin.req({
                    url: setter.timeAddress+"/fundIndexNotice/view",
                    method: "get",
                    async: false,
                    success: function (res) {
                        var str="";
                        $.each(res.data, function () {
                            str += "<li>"
                            str += "<div class=\"newsTimer\" > " +timeFormat(this.tradeDate)+" "+ this.tradeTime + "</div>";
                            str += "<div class=\"newsDetail\" > 鍚堢害: <span style='color: red'>" + this.code + "</span>" +
                                " 鏁版嵁鍛ㄦ湡:<span style='color: blue'>" + this.zhouqi + "</span> " +
                                " K绾跨被鍨�:<span style='color: green'>" + this.inform + "</span>  " +
                                "鍘嗗彶鑳滅巼:<span style='color: orange'>" + isNullBig(this.shenglv) + "</span>  " +
                                "骞磋儨鐜�:<span style='color: orange'>" + isNullBig(this.yearShenglv) + "</span> " +
                                "璇存槑:<span style='color: red'>" + this.tag + "</span></div>"
                            str += "</li>";
                        });
                        $("#newsTextId").html(str);
                        layer.open({
                            type: 1, // 寮瑰嚭灞傜被鍨嬶紝0涓洪粯璁ゆ牱寮忥紝1涓篿frame
                            id: times,
                            title: '淇℃伅鍒楄〃', // 寮瑰嚭灞傛爣棰�
                            content: $("#index_fund_notice_window"), // 寮瑰嚭灞傚唴瀹�
                            area: ['680px', '550px'] // 寮瑰嚭灞傚�介珮
                            , success: function () {
                                form.render();
                            },end:function (){
                                $("#index_fund_notice_window").html("");
                            }
                        });
                        form.on('switch(fund_index_notice_flag1)', function (data) {
                            updOpenPop(data);
                        });
                        form.on('switch(fund_index_notice_flag2)', function (data) {
                            updOpenPop(data);
                        });
                        form.on('switch(fund_index_notice_flag3)', function (data) {
                            updOpenPop(data);
                        });
                        form.on('switch(fund_index_notice_flag4)', function (data) {
                            updOpenPop(data);
                        });
                        function updOpenPop(data){
                            var noteType='';
                            $(".index-notice-button-kpi").each(function (){
                                if(!$(this).hasClass("index_notice_button_un_checked")){
                                    noteType=$(this).attr("text_name");
                                }
                            })
                            if(data.elem.checked) {
                                console.log($(data.elem).attr("lay-text"));
                                if($(data.elem).attr("lay-text").indexOf("寮圭獥")>-1) {
                                    admin.req({
                                        url: setter.timeAddress + "/noticeUser/delOpen",
                                        data: {
                                            userId: window.userId,
                                            userName: window.userName,
                                            noticeType: noteType,
                                            isOpen: 1
                                        },
                                        method: "get",
                                        async: false,
                                        success: function (res) {
                                            if (res.code === 0) {
                                                layer.msg("鎵撳紑鎴愬姛");
                                            } else {
                                                data.elem.checked = true;
                                            }
                                        }
                                    });
                                }else{
                                    document.getElementById("fund_pop_notice").play();
                                    admin.req({
                                        url: setter.timeAddress + "/noticeUser/delPop",
                                        data: {
                                            userId: window.userId,
                                            userName: window.userName,
                                            noticeType: noteType,
                                            isOpen: 1
                                        },
                                        method: "get",
                                        async: false,
                                        success: function (res) {
                                            if (res.code === 0) {
                                                layer.msg("鎵撳紑鎴愬姛");
                                            } else {
                                                data.elem.checked = true;
                                            }
                                        }
                                    });
                                }
                            }else{
                                console.log($(data.elem).attr("lay-text"));
                                if($(data.elem).attr("lay-text").indexOf("寮圭獥")>-1) {
                                    admin.req({
                                        url: setter.timeAddress + "/noticeUser/addOpen",
                                        data: {
                                            userId: window.userId,
                                            userName: window.userName,
                                            noticeType: noteType,
                                            isOpen: 1
                                        },
                                        method: "get",
                                        async: false,
                                        success: function (res) {
                                            if (res.code === 0) {
                                                layer.msg("鍏抽棴鎴愬姛");
                                            } else {
                                                data.elem.checked = false;
                                            }
                                        }
                                    });
                                }else{
                                    admin.req({
                                        url: setter.timeAddress + "/noticeUser/addPop",
                                        data: {
                                            userId: window.userId,
                                            userName: window.userName,
                                            noticeType: noteType,
                                            isPop: 1
                                        },
                                        method: "get",
                                        async: false,
                                        success: function (res) {
                                            if (res.code === 0) {
                                                layer.msg("鍏抽棴鎴愬姛");
                                            } else {
                                                data.elem.checked = false;
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
            })

            function timeFormat(time) {
                var datetime = new Date();
                datetime.setTime(time);
                var year = datetime.getFullYear();
                var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
                var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
                return year + "-" + month + "-" + date;
            }
            $(document).off("click",".index-notice-button-kpi").on("click",".index-notice-button-kpi",function (){
                if($(this).text()==="鏃ュ唴浣庨��"){
                    $("#index-notice-button-kpi-dis2").show();
                    $("#index-notice-button-kpi-dis").hide();
                    var str2 = "";
                    var newDate = new Date();
                    for(var i=0;i<=20;i++) {
                        if(i>0) {
                            newDate.setDate(newDate.getDate() - 1);
                        }
                        admin.req({
                            url: "http://10.168.10.30:8080//tradeChannel/orders?tradeChannel=2&date=" + timeFormat(newDate.getTime()),
                            method: "get",
                            async: false,
                            success: function (res) {
                                $.each(res.result, function () {
                                    var targetDate=new Date(this.createTime);
                                    var hours = targetDate.getHours();
                                    if(hours>=9 && hours<15) {
                                        str2 += "<li>"
                                        str2 += "<div class=\"newsTimer\" > " + this.createTime + "</div>";
                                        str2 += "<div class=\"newsDetail\" > 鍚堢害: <span style='color: red;padding-right: 30px;'>" + this.instrument + "</span>" +
                                            " 寮�骞充粨:<span style='color: green;padding-right: 30px;'>" + (this.offsot === "close" ? "骞充粨" : "寮�浠�") + "</span>  " +
                                            " 鏂瑰悜:<span style='color: blue;padding-right: 30px;'>" + (this.direction === "sell" ? "绌�" : "澶�") + "</span> " +
                                            " 浜ゆ槗鏁伴噺:<span style='color: orange;padding-right: 30px';> " + (this.number) + "</span>  " +
                                            " 鎴愪氦鏁伴噺:<span style='color: orange;padding-right: 30px';> " + (this.tradeNumber) + "</span> " +
                                            " 澶辫触鏁伴噺:<span style='color: red'>" + (this.cancelNumber) + "</span></div>"
                                        str2 += "</li>";
                                    }
                                });
                            }
                        });
                    }
                    $("#newsTextId").html(str2);
                    $(".index-notice-button-kpi").addClass("index_notice_button_un_checked");
                    $(this).removeClass("index_notice_button_un_checked");
                }else{
                    $("#index-notice-button-kpi-dis2").hide();
                    $("#index-notice-button-kpi-dis").show();
                    admin.req({
                        url: setter.timeAddress+"/fundIndexNotice/view",
                        method: "get",
                        async: false,
                        success: function (res) {
                            var str2 = "";
                            $.each(res.data, function () {
                                str2 += "<li>"
                                str2 += "<div class=\"newsTimer\" > " +timeFormat(this.tradeDate)+" "+ this.tradeTime + "</div>";
                                str2 += "<div class=\"newsDetail\" > 鍚堢害: <span style='color: red'>" + this.code + "</span>" +
                                    " 鏁版嵁鍛ㄦ湡:<span style='color: blue'>" + this.zhouqi + "</span> " +
                                    " K绾跨被鍨�:<span style='color: green'>" + this.inform + "</span>  " +
                                    "鍘嗗彶鑳滅巼:<span style='color: orange'>" + isNullBig(this.shenglv) + "</span>  " +
                                    "骞磋儨鐜�:<span style='color: orange'>" + isNullBig(this.yearShenglv) + "</span> " +
                                    "璇存槑:<span style='color: red'>" + this.tag + "</span></div>"
                                str2 += "</li>";
                            });
                            $("#newsTextId").html(str2);
                        }
                    });
                    $(".index-notice-button-kpi").addClass("index_notice_button_un_checked");
                    $(this).removeClass("index_notice_button_un_checked");
                }
            })

        }else{
            $("#floating-window").hide();
        }
    });
</script>
</body>
</html>
<style>
    .floating-window {
        width: 50px;
        height: 50px;
        background-color: indianred;
        border-radius: 50%;
        position: fixed;
        top: 94%;
        left: 97%;
        transform: translate(-50%, -50%);
        z-index: 9999;
        text-align: center;
        line-height: 50px;
        font-size: 12px;
        color: #fff;
        cursor:pointer;
    }
    .floating-window::before {
        content: "娑堟伅";
        display: inline-block;
        vertical-align: middle;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: indianred;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .index_span_width{
        display: inline-block;
        width: 130px;
    }
    .index_span_width_title{
        font-size: 14px;
        font-weight: bold;
    }
    .index_span_width_value{
        font-size: 14px;
        font-weight: bold;
        color: #1abc9c;
    }

    .index_span_width2{
        display: inline-block;
        width: 240px;
        color: red;
    }

    .newsText li .newsTimer {
        float: left;
        width: 550px;
        height: 30px;
        padding-left: 24px;
        background: url('../res/style/imgs/icon02.png') no-repeat 8px 7.5px;
        font-size: 14px;
        color: #706969;
    }

    .newsText{
        font-size: 12px;
        font-family: "Microsoft Yahei", "Hiragino Sans GB, STXihei, SimSun,Tahoma,Arial,sans-serif";
        margin-botto:10px;

    }
    .newsText li {
        border-bottom: 1px solid #e6e6e6;
        padding-top: 15px;
        overflow: hidden;
    }

    .newsText li .newsDetail {
        float: left;
        margin-left: 10px;
        margin-bottom: 10px;

    }

    #fund_notice_view ul li {
        list-style: none;
    }

    /* 鍚堢害棰滆壊 */
    .floating-window ul li div contract {
        color: red; /* 绾㈣壊 */
    }

    /* 鏁版嵁鍛ㄦ湡棰滆壊 */
    . floating-window ul li div data-cycle {
        color: blue; /* 钃濊壊 */
    }

    /* K绾跨被鍨嬮�滆壊 */
    .floating-window ul li div k-line-type {
        color: green; /* 缁胯壊 */
    }

    /* 鍘嗗彶鑳滅巼棰滆壊 */
    . floating-window ul li div history-win-rate {
        color: orange; /* 姗欒壊 */
    }
    .index_notice_button_un_checked{
        background-color:#bdc3c7;
    }
</style>


